package com.tjetc.reflect;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class _9ClassMethod {
    /*
         class相关的方法
     */
    public static void main(String[] args) throws ClassNotFoundException {
        /*
        1.获取全类名
        2.getSimpleName:获取简单类名
        3.getFields:获取所有public修饰的属性，包含本类以及父类的
        4.getDeclaredFields:获取本类中所有属性
        5.getMethods:获取所有public修饰的方法，包含本类以及父类的
        6.getDeclaredMethods:获取本类中所有方法
        7.getConstructors:获取本类所有public修饰的构造器
        8.getDeclaredConstructors:获取本类中所有构造器
        11.getInterfaces:以Class[]形式返回接口信息
        12.getAnnotations:以Annotation[]形式返回注解信息
         */
        Class cls = Class.forName("com.tjetc.reflect._1Cat");
        String simpleName = cls.getSimpleName();
        System.out.println(simpleName);
        System.out.println("-------------------------------");
        Field[] fields = cls.getFields();
        for (Field field : fields) {
            System.out.println(field.getName() + "-");
        }
        System.out.println("-------------------------------");
        // 注意：该方法只能获取本类的所有成员属性
        Field[] declaredFields = cls.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println("-" + declaredField.getName());
        }
        System.out.println("-------------------------------");
        Method[] methods = cls.getMethods();
        for (Method method2 : methods) {
            System.out.println(method2.getName());
        }
        System.out.println("-------------------------------");
        Method[] declaredMethods = cls.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod.getName());
        }
        System.out.println("-------------------------------");
        Constructor[] declaredConstructors = cls.getDeclaredConstructors();
        for (Constructor declaredConstructor : declaredConstructors) {
            // 这里只获取了名字
            System.out.println(declaredConstructor.getName());
        }
        System.out.println("-------------------------------");
        Class[] interfaces1 = cls.getInterfaces();
        for (Class aClass : interfaces1) {
            System.out.println(aClass.getName());
        }
        System.out.println("-------------------------------");
        Annotation[] annotations = cls.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }
    }
}
